package demo2_clone;

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person(12);
        //拷贝
        Person person2 = (Person) person1.clone();
        //但会有错误，因为还没有处理异常,让main上throws掉。但此刻类型会不匹配，需要强转
        //clone的返回类型是祖先类Object，而这里person2是子类，子类给到父类所以需要强转


        System.out.println(person1.m.money);
        System.out.println(person2.m.money);
        System.out.println("==================");
        person2.m.money = 100;
        System.out.println(person1.m.money);
        //此刻两个值都变化了，属于浅拷贝，两个地址同时在拷贝同一个值,但在Money类和Person中修改clone方法使其完成深拷贝
        System.out.println(person2.m.money);

    }
}